﻿Class ActorCommandStatusObserver
    Implements Observer

    Private progressBar As ProgressBar
    Private actor As Receiver

    Sub New(ByRef aProgressBar As ProgressBar, ByVal aReceiver As Receiver)
        actor = aReceiver
        progressBar = aProgressBar
        actor.Register(Me)
        setEmptyProgressBar()
    End Sub

    Sub Notify() Implements Observer.Notify
        Dim command As Command = actor.getCurrentCommand()
        If command Is Nothing OrElse command.isIdle Then
            setEmptyProgressBar()
        ElseIf Not command.hasFinalized Then
            stepProgressBar(command)
        End If
    End Sub

    Private Sub stepProgressBar(ByVal command As Command)
        progressBar.Maximum = command.getTotalEstimation() - 1
        progressBar.PerformStep()
    End Sub

    Private Sub setEmptyProgressBar()
        progressBar.Value = 0
        progressBar.Maximum = 10
        progressBar.Step = 1
        progressBar.Value = 0
    End Sub

    Private Sub initilalizeProgressBar()
        progressBar.Minimum = 0
        progressBar.Maximum = 10
        progressBar.Step = 1
        progressBar.Value = 0
    End Sub

End Class
